package com.loan.controller.app.pay;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.enums.PayCompanyEnum;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.CompanyEntity;
import com.loan.system.domain.PayConfigEntity;
import com.loan.system.service.PayConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang
 * @date 2022年09月22日 0:04
 */
@Validated
@Api(value = "支付通道管理", tags = {"支付通道管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/payConfig")
public class PayConfigController extends BaseController {

    private final PayConfigService payConfigService;

    /**
     * 获取支付通道列表(分页)
     */
    @ApiOperation("获取支付通道列表(分页)")
    //@SaCheckPermissio("app:payConfig:list")
    @GetMapping("/page")
    public TableDataInfo<PayConfigEntity> page(PayConfigEntity entity, PageQuery pageQuery) {
        return payConfigService.selectPageList(entity, pageQuery);
    }

    /**
     * 获取支付通道列表
     */
    @ApiOperation("获取支付通道列表")
    //@SaCheckPermissio("app:payConfig:list")
    @GetMapping("/list")
    public Result<List<PayConfigEntity>> list() {
        return Result.ok(payConfigService.selectList());
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:payConfig:query")
    @GetMapping(value = {"/{id}"})
    public Result<PayConfigEntity> getInfo(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(payConfigService.selectPayConfigById(id));
    }

    /**
     * 新增支付通道
     */
    @ApiOperation("新增支付通道")
    //@SaCheckPermissio("app:payConfig:add")
    @Log(title = "新增支付通道", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody PayConfigEntity entity) {
        return toAjax(payConfigService.addPayConfig(entity));
    }

    /**
     * 修改支付通道
     */
    @ApiOperation("修改支付通道")
    //@SaCheckPermissio("app:payConfig:update")
    @Log(title = "修改支付通道", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody PayConfigEntity entity) {
        return toAjax(payConfigService.updatePayConfig(entity));
    }

    /**
     * 删除支付通道
     */
    @ApiOperation("删除支付通道")
    //@SaCheckPermissio("app:payConfig:remove")
    @Log(title = "删除支付通道", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(payConfigService.deleteConfigById(id));
    }

    /**
     * 状态修改
     */
    @ApiOperation("状态修改")
    //@SaCheckPermissio("app:payConfig:edit")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody PayConfigEntity entity) {
        return toAjax(payConfigService.updateStatus(entity));
    }

    @ApiOperation("获取支付公司列表")
    //@SaCheckPermissio("app:payConfig:query")
    @GetMapping(value = "/getPayCompanyList")
    public Result<List> getPayCompanyList(){
        return Result.ok(PayCompanyEnum.getList());
    }
}
